package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("userShopController")
@RequestMapping("/user/shop")
@Api(tags = "店铺相关")
@Slf4j
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 获取店铺营业状态
     *
     * @return
     */
    @GetMapping("/status")
    @ApiOperation("获取店铺营业状态")
    public Result<Integer> getStatus() {
        // 从Redis获取店铺状态
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get("SHOP_STATUS");

        // 处理空值情况，默认返回0（打烊状态）
        if (shopStatus == null) {
            log.warn("未从Redis中获取到店铺状态，使用默认值：打烊");
            shopStatus = 0; // 0表示打烊，1表示营业，根据实际业务定义调整
        } else {
            log.info("店铺：{}", shopStatus == 1 ? "在上班" : "打烊了");
        }

        return Result.success(shopStatus);
    }
}
